home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-07-29 | 3.0 KB | 97 lines | [TEXT/MPS ] |
- #include <types.h>
- #include <Quickdraw.h>
- #include <Memory.h>
- #include <Files.h>
- #include <Resources.h>
- #include <Packages.h>
- #include <String.h>
- #include <Strings.h>
- #include <ToolUtils.h>
- #include "THyperXCmd.h"
-
- Handle BuildPathname (TXCMDBlock *myParamPtr, StringPtr fName, short vRefNum)
- {
-
- /*
- This function is adapted from the FileToField XCMD in the Dartmouth XCMDs.
- Given the name of a file and vRefNum as provided by SFGetFile, returns a
- StringHandle containing the full path to the file.
- */
-
- char fullPathName[256], tempStr[256];
- short theErr;
- register HParmBlkPtr myParamBlock=nil;
- register CInfoPBPtr myCInfoPB=nil;
- register WDPBPtr myWDPB=nil;
-
- if (myParamBlock=(HParmBlkPtr)NewPtr(sizeof(HParamBlockRec)))
- {
- /*
- Get the name of the volume pointed to by the vRefNum
- */
- myParamBlock->volumeParam.ioNamePtr = (StringPtr)&tempStr;
- myParamBlock->volumeParam.ioCompletion = nil;
- myParamBlock->volumeParam.ioVRefNum = vRefNum;
- myParamBlock->volumeParam.ioVolIndex = 0;
-
- if (theErr=PBHGetVInfo(myParamBlock, false))
- myParamPtr->SignalFileErr(theErr);
- else
- {
- /*
- Now we need the Working Directory (WD) information because we're
- going to step backwards from the file through all of the folders until
- we reach the root directory.
- */
- myWDPB=(WDPBPtr)myParamBlock;
- myWDPB->ioVRefNum = vRefNum;
- myWDPB->ioWDProcID = 0;
- myWDPB->ioWDIndex = 0;
- if (theErr=PBGetWDInfo(myWDPB, false))
- myParamPtr->SignalFileErr(theErr);
- else
- {
- myCInfoPB=(CInfoPBPtr)myParamBlock;
- myCInfoPB->dirInfo.ioFDirIndex = -1;
- if (theErr=PBGetCatInfo(myCInfoPB, false))
- myParamPtr->SignalFileErr(theErr);
- else
- {
- /*
- Here starts the real work -- start to climb the tree by continually
- looking in the ioDrParID field for the next directory above until we fail...
- */
- myCInfoPB->dirInfo.ioDrDirID=myCInfoPB->dirInfo.ioDrParID;
- p2cstr(myCInfoPB->dirInfo.ioNamePtr);
- strcpy(fullPathName, (char *)myCInfoPB->dirInfo.ioNamePtr);
- strcat(fullPathName, ":");
- p2cstr(fName);
- strcat(fullPathName, (char *)fName);
- while (myCInfoPB->dirInfo.ioDrParID)
- {
- myCInfoPB->dirInfo.ioDrDirID=myCInfoPB->dirInfo.ioDrParID;
- /*
- Be careful of an error returned here -- it means the user chose a file on the
- desktop level of this volume. If this is the case, just stop here and return
- "VolumeName:FileName"; otherwise loop until failure.
- */
- if(theErr=PBGetCatInfo(myCInfoPB, false)==noErr)
- {
- p2cstr(myCInfoPB->dirInfo.ioNamePtr);
- strcpy(tempStr, (char *)myCInfoPB->dirInfo.ioNamePtr);
- strcat(tempStr, ":");
- strcat(tempStr, fullPathName);
- strcpy(fullPathName, tempStr);
- }
- else
- break;
- }
- return (myParamPtr->PasToZero((StringPtr)c2pstr(fullPathName)));
- } /*if PBGetCatInfo worked OK*/
- } /*if PBHGetVInfo worked OK*/
- } /*if PBGetWDInfo worked OK*/
- DisposPtr((Ptr)myParamBlock);
- } /*if we had enough room for a new pointer*/
- return (nil);
- }
-